// import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_base/config/app_color.dart';
import 'package:flutter_base/http/http_export.dart';
import 'package:flutter_base/utils/loading/loading_utils.dart';
import 'package:flutter_base/utils/picture/image_picker_utils.dart';
import 'package:flutter_base/widgets/widget_line.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';

class ImagePickSelectSheet extends StatelessWidget {
  const ImagePickSelectSheet({super.key});

  Future show() async {
    await Get.bottomSheet(
      this,
      isScrollControlled: true,
      // barrierColor: Colors.black.withOpacity(0.4),
      backgroundColor: Colors.white,
    );
  }

  @override
  Widget build(BuildContext context) {
    var list = ["拍照", "从手机相册选择"];
    return SafeArea(
        child: Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        // WidgetLine()
        ...list.map((e) => InkWell(
              onTap: () async {
                AssetEntity? assetEntity;
                if (list.indexOf(e) == 1) {
                  assetEntity =
                      (await ImagePickerUtils.picker(1, []))?.firstOrNull;
                } else {
                  assetEntity = await ImagePickerUtils.camera();
                }
                if (assetEntity != null) {
                  // File? file =  await  assetEntity.file;
                  HttpResponse response = await ImagePickerUtils.uploadFileData(
                      filePath: (await assetEntity.file)!.path);
                  if (response.isSuccess) {


                  } else {
                    LoadingUtils.showToast(response.message);
                  }
                }
                // Get.back(result: list.indexOf(e));
              },
              child: Container(
                decoration: BoxDecoration(
                    border: Border(
                        bottom: BorderSide(
                            width: 1.w, color: AppColor.colorEBF0F5))),
                alignment: Alignment.center,
                height: 52.w,
                child: Text(
                  e,
                  style: TextStyle(
                    color: AppColor.color282828,
                    fontSize: 16.sp,
                    fontWeight: FontWeight.w600,
                  ),
                  textAlign: TextAlign.center,
                ),
              ),
            )),
        InkWell(
          onTap: () {
            Get.back();
          },
          child: Container(
            height: 52.w,
            alignment: Alignment.center,
            child: Text(
              "取消",
              style: TextStyle(
                color: AppColor.color999999,
                fontSize: 16.sp,
                fontWeight: FontWeight.w600,
              ),
              textAlign: TextAlign.center,
            ),
          ),
        ),
      ],
    ));
  }
}
